package com.atmilan.quartz.model.entity.buyer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 *
 * </p>
 *
 * @author hupeng
 * @since 2020-04-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class BuyerProductSkuMerged extends Model<BuyerProductSkuMerged> {

    private static final long serialVersionUID = 1L;

    /**
     * SKU ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private String id;

    /**
     * SKU ID
     */
    private String skuId;

    /**
     * 商品ID
     */
    private String goodsId;

    /**
     * 库存数量
     */
    private Integer stock;

    /**
     * 颜色
     */
    private String color;

    /**
     * 尺码
     */
    private String size;

    /**
     * 1是期货， 0是现货
     */
    private Integer qihuo;

    /**
     * 更新标记 0 未改变 1 新增 2 更新
     */
    private Integer updateFlag = 1;
    /**
     * 采集时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd  HH:mm:ss")
    private Date createTime;
    /**
     * 采集时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd  HH:mm:ss")
    private Date editTime;

    @Override
    protected Serializable pkVal() {
        return this.goodsId + this.skuId;
    }

    private String suk;

    public String getSuk() {
        if (StringUtils.isNotBlank(suk)) {
            return suk;
        }
        List<String> sukList = new ArrayList<String>();
        if (StringUtils.isNotBlank(color)) {
            sukList.add(color);
        }
        if (StringUtils.isNotBlank(size)) {
            sukList.add(size);
        }
        return String.join(",", sukList);
    }

    @JsonIgnore
    public String getKey() {
        return this.goodsId + "-" + StringUtils.defaultString(this.color, "") + "-" + StringUtils.defaultString(this.size, "");
    }
    
}
